package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    @Select("select count(*) from dish where category_id=#{id}")
    Integer countByCategoryId(Long id);

    /**
     * 新增菜品
     *
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void add(Dish dish);

    Page<Dish> page(DishPageQueryDTO dto);

    @Select("select *from dish where name=#{name}")
    Dish getByName(String name);

    /**
     * 根据id查询菜品
     *
     * @param id
     * @return
     */
    @Select("select *from dish where id=#{id}")
    Dish selectById(Long id);

    /**
     * 根据id删除菜品
     *
     * @param dishIds
     */
    void deleteById(List<Long> dishIds);

    /**
     * 修改菜品
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void updateDishById(Dish dish);

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @Select("select *from dish where category_id=#{categoryId}")
    List<Dish> list(Long categoryId);

    @Select("select dish.* from dish left join setmeal_dish on dish.id=setmeal_dish.dish_id " +
            "where setmeal_id=#{id} ")
    List<Dish> getDishBySetmealId(Long id);
    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
